home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / Gadgets / EditText.p < prev    next >
Encoding:
Text File  |  1998-10-30  |  9.6 KB  |  465 lines  |  [TEXT/CWIE]

  1. { EditText.p }
  2. { Created 10/30/98 1:04 PM by AppMaker }
  3.  
  4. Unit EditText;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     Menus,
  15.     Resources,
  16.     TextEdit,
  17.     ToolUtils,
  18.  
  19.     DDocData,
  20.     GadgetsEngine,
  21.     GadgetsDoc,
  22.     AMWindow;
  23.  
  24. type
  25.     EditText        = object (AMWindow)
  26.  
  27.     {data members}
  28.         mData:            DDocData;
  29.         mSmallHandle:        ControlHandle;
  30.         mLargeHandle:        ControlHandle;
  31.         mX12345Handle:        ControlHandle;
  32.         mX12345e6Handle:        ControlHandle;
  33.         mPasswordHandle:        ControlHandle;
  34.         mDateHandle:        ControlHandle;
  35.         mTimeHandle:        ControlHandle;
  36.         mStyledHandle:        ControlHandle;
  37.  
  38.     {methods}
  39.         Procedure Initialize; Override;
  40.  
  41.         Procedure Open        (inDoc:        GadgetsDoc;
  42.                              inData:    DDocData);
  43.         Procedure Close; Override;
  44.  
  45.         Procedure Control    (whichControl:    ControlHandle;
  46.                               whichPart:        integer;
  47.                              where:            Point); Override;
  48.         Procedure MouseIn    (where:            Point;
  49.                              modifiers:        integer); Override;
  50.         Procedure TypeIn    (charCode:        SInt16); Override;
  51.         Procedure ExitCurField; Override;
  52.         Procedure DataChanged    (inDataID:    longint); Override;
  53.         Procedure Resize; Override;
  54.         Procedure Scroll    (newValue:        integer;
  55.                              oldValue:        integer); Override;
  56.  
  57.         Function  GetEngine: GadgetsEngine;
  58.  
  59. {$ifc false}
  60.         Procedure UpdateMenus; Override;
  61. {$endif}
  62.         Function  DoCommand        (inCommand:    longint): Boolean; Override;
  63.  
  64.         Procedure DoUndo;
  65.         Procedure DoCut;
  66.         Procedure DoCopy;
  67.         Procedure DoPaste;
  68.         Procedure DoClear;
  69.         Procedure DoSelectAll;
  70.         Procedure DoShowClipboard;
  71.  
  72.     end;
  73.  
  74. {----------}
  75. Procedure CreateEditText    (inDoc:        GadgetsDoc;
  76.                              inData:    DDocData);
  77.  
  78. {----------}
  79. Implementation
  80.  
  81. Uses
  82.     Globals,
  83.     ResourceDefs,
  84.     DoScrap,
  85.     Scrolling,
  86.     ControlUtils,
  87.     Miscellany;
  88.  
  89. const
  90.     kSmallField        = 1;
  91.     kLargeField        = 2;
  92.     kX12345Field        = 3;
  93.     kX12345e6Field        = 4;
  94.     kPasswordField        = 5;
  95.     kDateField        = 6;
  96.     kTimeField        = 7;
  97.     kStyledField        = 8;
  98.  
  99. {----------}
  100. Procedure CreateEditText (
  101.     inDoc:        GadgetsDoc;
  102.     inData:        DDocData);
  103. var
  104.     winObj:        EditText;
  105. begin
  106.     winObj := nil;
  107.     New (winObj);
  108.  
  109.     if winObj <> nil then begin
  110.         winObj.Initialize;
  111.         winObj.Open (inDoc, inData);
  112.     end;
  113. end;
  114.  
  115. {----------}
  116. Procedure EditText.Initialize;
  117. begin
  118.     Inherited Initialize;
  119. end;
  120.  
  121. {----------}
  122. Function  EditText.GetEngine: GadgetsEngine;
  123. begin
  124.     GetEngine := GadgetsEngine (mDoc.mEngine);
  125. end;
  126.  
  127. {----------}
  128. Procedure EditText.Open (
  129.     inDoc:        GadgetsDoc;
  130.     inData:        DDocData);
  131. var
  132.     window:        WindowPtr;
  133.     wftb:        Handle;
  134.     errCode:    OSErr;
  135. begin
  136.     mDoc := inDoc;
  137.     mData := inData;
  138.     mData.AddResponder (self);
  139.  
  140.     window := GetNewCWindow (WIND_EditText, nil, WindowPtr (-1));
  141.     if inDoc.mEngine.GetFilename <> '' then begin
  142.         SetWTitle (window, inDoc.mEngine.GetFilename);
  143.     end;
  144.     mWindow := window;
  145.     GadgetsDoc (mDoc).mEditTextPtr := window;
  146.  
  147.     WindowPeek (window)^.windowKind := kAMWindowFlag;
  148.     SetWRefCon (window, ord4 (self));
  149.     SetPort (window);
  150.     SetInfo (window);
  151.  
  152.     wftb := GetResource ('Wftb', WIND_EditText);
  153.  
  154.     errCode := CreateRootControl (window, mRootControl);
  155.  
  156.     vScroll := nil;
  157.     hScroll := nil;
  158.  
  159.  
  160.     mSmallHandle := GetNewControl (CNTL_Small, window);
  161.     SetWindowItemFont (mSmallHandle, wftb, 1);
  162.     SetControlText (mSmallHandle, mData.GetSmall);
  163.  
  164.     mLargeHandle := GetNewControl (CNTL_Large, window);
  165.     SetWindowItemFont (mLargeHandle, wftb, 2);
  166.     SetControlText (mLargeHandle, mData.GetLarge);
  167.  
  168.     mX12345Handle := GetNewControl (CNTL_X12345, window);
  169.     SetWindowItemFont (mX12345Handle, wftb, 3);
  170.     SetControlTextValue (mX12345Handle, mData.GetX12345);
  171.  
  172.     mX12345e6Handle := GetNewControl (CNTL_X12345e6, window);
  173.     SetWindowItemFont (mX12345e6Handle, wftb, 4);
  174.     SetControlTextFloat (mX12345e6Handle, mData.GetX12345e6);
  175.  
  176.     mPasswordHandle := GetNewControl (CNTL_Password, window);
  177.     SetWindowItemFont (mPasswordHandle, wftb, 5);
  178.     SetControlText (mPasswordHandle, mData.GetPassword);
  179.  
  180.     mDateHandle := GetNewControl (CNTL_Date, window);
  181.     SetWindowItemFont (mDateHandle, wftb, 6);
  182.     SetClockDateTime (mDateHandle, mData.GetTheDate);
  183.  
  184.     mTimeHandle := GetNewControl (CNTL_Time, window);
  185.     SetWindowItemFont (mTimeHandle, wftb, 7);
  186.     SetClockDateTime (mTimeHandle, mData.GetTheTime);
  187.  
  188.     mStyledHandle := GetNewControl (CNTL_Styled, window);
  189.     SetWindowItemFont (mStyledHandle, wftb, 8);
  190.     SetControlText (mStyledHandle, mData.GetStyled);
  191.  
  192.     errCode := AdvanceKeyboardFocus (window);
  193.  
  194.     ShowWindow (window);
  195. end;
  196.  
  197. {----------}
  198. Procedure EditText.Close;
  199. begin
  200.     mData.RemoveResponder (self);
  201.  
  202.     GadgetsDoc (mDoc).mEditTextPtr := nil;
  203.     SetInfo (nil);
  204.     HideWindow (mWindow);
  205.     DisposeWindow (mWindow);
  206.  
  207.     Dispose (self);
  208. end;
  209.  
  210. {----------}
  211. Procedure EditText.Control (
  212.     whichControl:    ControlHandle;
  213.     whichPart:        integer;
  214.     where:            Point);
  215. var
  216.     bounds:            Rect;
  217.     newValue:        integer;
  218.     partcode:        SInt16;
  219. begin
  220.     ExitCurField ();
  221.  
  222.     if whichControl = mSmallHandle then begin
  223.         HandleEditClick (mSmallHandle, where);
  224.     end;
  225.     if whichControl = mLargeHandle then begin
  226.         HandleEditClick (mLargeHandle, where);
  227.     end;
  228.     if whichControl = mX12345Handle then begin
  229.         HandleEditClick (mX12345Handle, where);
  230.     end;
  231.     if whichControl = mX12345e6Handle then begin
  232.         HandleEditClick (mX12345e6Handle, where);
  233.     end;
  234.     if whichControl = mPasswordHandle then begin
  235.         HandleEditClick (mPasswordHandle, where);
  236.     end;
  237.     if whichControl = mDateHandle then begin
  238.         HandleEditClick (mDateHandle, where);
  239.     end;
  240.     if whichControl = mTimeHandle then begin
  241.         HandleEditClick (mTimeHandle, where);
  242.     end;
  243.     if whichControl = mStyledHandle then begin
  244.         HandleEditClick (mStyledHandle, where);
  245.     end;
  246. end;
  247.  
  248. {----------}
  249. Procedure EditText.DataChanged (
  250.     inDataID:        longint);
  251. begin
  252.     if inDataID = idSmall then begin
  253.         SetControlText (mSmallHandle, mData.GetSmall);
  254.     end;
  255.     if inDataID = idLarge then begin
  256.         SetControlText (mLargeHandle, mData.GetLarge);
  257.     end;
  258.     if inDataID = idX12345 then begin
  259.         SetControlTextValue (mX12345Handle, mData.GetX12345);
  260.     end;
  261.     if inDataID = idX12345e6 then begin
  262.         SetControlTextFloat (mX12345e6Handle, mData.GetX12345e6);
  263.     end;
  264.     if inDataID = idPassword then begin
  265.         SetControlText (mPasswordHandle, mData.GetPassword);
  266.     end;
  267.     if inDataID = idTheDate then begin
  268.         SetClockDateTime (mDateHandle, mData.GetTheDate);
  269.     end;
  270.     if inDataID = idTheTime then begin
  271.         SetClockDateTime (mTimeHandle, mData.GetTheTime);
  272.     end;
  273.     if inDataID = idStyled then begin
  274.         SetControlText (mStyledHandle, mData.GetStyled);
  275.     end;
  276. End;
  277.  
  278. {----------}
  279. Procedure EditText.MouseIn (
  280.     where:            Point;
  281.     modifiers:        integer);
  282. var
  283.     bounds:            Rect;
  284. begin
  285. end;
  286.  
  287. {----------}
  288. Procedure EditText.ExitCurField;
  289. var
  290.     errCode:    OSErr;
  291.     focus:        ControlHandle;
  292. begin
  293.     errCode := GetKeyboardFocus (mWindow, focus);
  294.  
  295.     if focus = nil then begin
  296.         { nothing to exit }
  297.  
  298.     end else if focus = mSmallHandle then begin
  299.         mData.SetSmall (GetEditTextStr (mSmallHandle));
  300.     end else if focus = mLargeHandle then begin
  301.         mData.SetLarge (GetEditTextChars (mLargeHandle));
  302.     end else if focus = mX12345Handle then begin
  303.         mData.SetX12345 (GetControlTextValue (mX12345Handle));
  304.     end else if focus = mX12345e6Handle then begin
  305.         mData.SetX12345e6 (GetControlTextFloat (mX12345e6Handle));
  306.     end else if focus = mPasswordHandle then begin
  307.         mData.SetPassword (GetEditTextPasswordStr (mPasswordHandle));
  308.     end else if focus = mDateHandle then begin
  309.         mData.SetTheDate (GetClockDateTime (mDateHandle));
  310.     end else if focus = mTimeHandle then begin
  311.         mData.SetTheTime (GetClockDateTime (mTimeHandle));
  312.     end else if focus = mStyledHandle then begin
  313.         mData.SetStyled (GetEditTextChars (mStyledHandle));
  314.     end;
  315.     inherited ExitCurField;
  316. end;
  317.  
  318. {----------}
  319. Procedure EditText.TypeIn (
  320.     charCode:    SInt16);
  321. var
  322.     ch:            char;
  323.     errCode:    OSErr;
  324.     focus:        ControlHandle;
  325.     keyCode:    SInt16;
  326.     partcode:    SInt16;
  327. begin
  328.     errCode := GetKeyboardFocus (mWindow, focus);
  329.  
  330.     ch := chr (charCode);
  331.     if (ch = charEnter)
  332.     |  (ch = charReturn) then begin
  333.         ExitCurField;
  334.     end else if ch = charEsc then begin
  335.     end else if ch = charTab then begin
  336.         DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
  337.     end else if focus <> nil then begin
  338.         keyCode := BAnd (curEvent.message, keyCodeMask);
  339.         partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
  340.         mDoc.mEngine.SetDirty;
  341.     end else begin
  342.         SysBeep (1);
  343.     end;
  344. end;
  345.  
  346. {----------}
  347. Procedure EditText.Resize;
  348. begin
  349.     { application-specific code to resize items in window }
  350. end;
  351.  
  352. {----------}
  353. Procedure EditText.Scroll (
  354.     newValue:    integer;
  355.     oldValue:    integer);
  356. begin
  357.     { application-specific code to scroll window }
  358.     if gWhichScroll = vScroll then begin
  359.     end else begin    { horizontal }
  360.     end;
  361. end;
  362.  
  363. {----------}
  364. Procedure EditText.DoUndo;
  365. begin
  366. end; {DoUndo}
  367.  
  368. {----------}
  369. Procedure EditText.DoCut;
  370. var
  371.     curTE:        TEHandle;
  372. begin
  373.     curTE := GetCurTE ();
  374.  
  375.     if curTE <> nil then begin
  376.         TECut (curTE);
  377.         mDoc.mEngine.SetDirty;
  378.         scrapDirty := true;
  379.     end;
  380. end; {DoCut}
  381.  
  382. {----------}
  383. Procedure EditText.DoCopy;
  384. var
  385.     curTE:        TEHandle;
  386. begin
  387.     curTE := GetCurTE ();
  388.  
  389.     if curTE <> nil then begin
  390.         TECopy (curTE);
  391.         scrapDirty := true;
  392.     end;
  393. end; {DoCopy}
  394.  
  395. {----------}
  396. Procedure EditText.DoPaste;
  397. var
  398.     curTE:        TEHandle;
  399. begin
  400.     curTE := GetCurTE ();
  401.  
  402.     if curTE <> nil then begin
  403.         TEPaste (curTE);
  404.         mDoc.mEngine.SetDirty;
  405.     end;
  406. end; {DoPaste}
  407.  
  408. {----------}
  409. Procedure EditText.DoClear;
  410. var
  411.     curTE:        TEHandle;
  412. begin
  413.     curTE := GetCurTE ();
  414.  
  415.     if curTE <> nil then begin
  416.         TEDelete (curTE);
  417.         mDoc.mEngine.SetDirty;
  418.     end;
  419. end; {DoClear}
  420.  
  421. {----------}
  422. Procedure EditText.DoSelectAll;
  423. var
  424.     curTE:        TEHandle;
  425. begin
  426.     curTE := GetCurTE ();
  427.  
  428.     if curTE <> nil then begin
  429.         TESetSelect (0, 32767, curTE);
  430.     end;
  431. end; {DoSelectAll}
  432.  
  433. {----------}
  434. Procedure EditText.DoShowClipboard;
  435. begin
  436. end; {DoShowClipboard}
  437.  
  438. {----------}
  439. Function EditText.DoCommand (
  440.     inCommand:        longint): Boolean;
  441. begin
  442.     DoCommand := true;
  443.     case inCommand of
  444.         cmdUndo:
  445.                 DoUndo;
  446.         cmdCut:
  447.                 DoCut;
  448.         cmdCopy:
  449.                 DoCopy;
  450.         cmdPaste:
  451.                 DoPaste;
  452.         cmdClear:
  453.                 DoClear;
  454.         cmdSelectAll:
  455.                 DoSelectAll;
  456.         cmdShowClipboard:
  457.                 DoShowClipboard;
  458.  
  459.         otherwise
  460.                 DoCommand := false;
  461.     end; {case}
  462. end;
  463.  
  464. end.
  465.